package com.atguigu.tingshu.order.pattern.factory;


import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.order.pattern.OrderConfirmPolicy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
@Component
@Slf4j
public class OrderConfirmFactory {

    /**
     * 自动发现 策略接口OrderConfirmPolicy下所有实现类对象 注入Map中 Map的Key是策略实现类对象BeanID Map的Value是策略实现类对象
     */
    @Autowired
    private Map<String, OrderConfirmPolicy> orderConfirmPolicyMap;


    public OrderConfirmPolicy getOrderConfirmPolicy(String itemType) {
        if (orderConfirmPolicyMap.containsKey(itemType)) {
            return orderConfirmPolicyMap.get(itemType);
        }
        throw new RuntimeException("未查询到该商品类型");
    }
}
